import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import Components from "unplugin-vue-components/vite";
import { VantResolver } from "unplugin-vue-components/resolvers";
import vueJsx from "@vitejs/plugin-vue-jsx";
import Pages from "vite-plugin-pages";

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  // console.log("cwd: ", process.cwd());
  const env = loadEnv(mode, process.cwd(), "");
  return {
    // define: {
    //   'process.env': {
    //     VITE_APP_BASE_URL: env.VITE_APP_BASE_URL,
    //   }
    // },
    base: "./", // 设置项目的公共基础路径
    server: {
      host: true,
      port: 8010,
      cors: true, // 允许跨域
      // 设置代理，根据项目实际情况配置
      proxy: {
        "/xnzAdminWeb": {
          target: "https://jindi.admin.qbclub.club",
          // target: "http://jindi.dcapi.qbclub.club/xnzCashLoanApi",
          // target:
          // "http://jindi.dcapi.qbclub.club/xnzCashLoanApi/cashloan/loanMarket",
          // target: "http://192.168.0.44:8093", // 黄磊,
          changeOrigin: true,
          // secure: false,
          rewrite: (path) => {
            // console.log("++++:", path);
            return path;
            console.log("++++replace:", path.replace("/xnzAdminWeb", ""));
            // return path.replace("/xnzAdminWeb", "");
            // return path.replace("/api", "/xnzAdminWeb");
          },
        },
      },
    },
    build: {
      outDir: "dist",
    },
    plugins: [
      Pages({
        dirs: "src/views", // 路由组件目录
        exclude: ["**/components/*.vue", "**/modules/*.vue"], // 排除组件
      }),
      vue(),
      vueJsx(),
      Components({
        resolvers: [VantResolver()],
      }),
    ],
    resolve: {
      alias: {
        "@": "/src",
      },
    },
  };
});
